package com.muyangren.poidemo.one;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class BytePictureUtils {

    /**
     * 将图片输入流转换为字节数组
     *
     * @param imageStream 图片文件的输入流
     * @return 包含图片数据的字节数组
     * @throws IOException 如果读取过程中发生错误
     */
    public static byte[] getBytes(InputStream imageStream) throws IOException {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        
        byte[] buffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = imageStream.read(buffer)) != -1) {
            outputStream.write(buffer, 0, bytesRead);
        }
        
        imageStream.close();
        return outputStream.toByteArray();
    }
}
